package cate.game.util;

public class IntervalCounter {
    private int interval;
    private int counter;
    private int delay;

    public void setInterval(int value) {
        this.interval = value;
        this.counter = 0;
    }

    public int getInterval() {
        return this.interval;
    }

    public IntervalCounter(int interval) {
        this(interval, 0);
    }

    public IntervalCounter(int interval, int delay){
        this.interval = 1;
        this.counter = 0;
        this.interval = interval;
        this.delay = delay;
    }

    public IntervalCounter() {
        this(0);
    }

    public boolean trigger() {
        if (this.interval <= 0) {
            return false;
        } else {
            if(delay > 0) {
                delay--;
                return false;
            }
            ++this.counter;
            if (this.counter >= this.interval) {
                this.counter = 0;
                return true;
            } else {
                return false;
            }
        }
    }
}